
//
//  FenXiangView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/2/25.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "FenXiangView.h"
#import "WXApi.h"
@implementation FenXiangView

-(void)creatView{
    self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    
    UIView *view=[UIView new];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(280);
    }];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.cornerRadius=4;
    
    UIView *topview=[UIView new];
    [view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    topview.backgroundColor=_backgroundColor;
    
    UILabel *label=[UILabel new];
    [topview addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    label.text=@"分享到";
    label.textColor=[UIColor whiteColor];
    label.font=[UIFont systemFontOfSize:18];
    
    NSArray *arr=[NSArray arrayWithObjects:@"微信好友",@"朋友圈",@"QQ好友",@"QQ空间", nil];
    for (int i=0; i<4; i++) {
        UIView *typeView=[UIView new];
        [view addSubview:typeView];
        [typeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(topview.mas_bottom);
            make.left.mas_equalTo(20+(_mainW-40)/4*i);
            make.width.mas_equalTo((_mainW-40)/4);
            make.height.mas_equalTo(160);
        }];
        
        typeView.tag=i;
        typeView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fenXian:)];
        [typeView addGestureRecognizer:tapGesture];
        
        UIImageView *imageView=[UIImageView new];
        [typeView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
            make.height.width.mas_equalTo(35);
        }];
        imageView.image=[UIImage imageNamed:arr[i]];
        
        UILabel *label2=[UILabel new];
        [typeView addSubview:label2];
        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(10);
        }];
        label2.text=arr[i];
        label2.font=[UIFont systemFontOfSize:15];
        label2.textColor=ColorWithRGB(149, 149, 149);
    }
    UIView *XianView=[UIView new];
    [view addSubview:XianView];
    [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-60);
        make.height.mas_equalTo(1);
    }];
    XianView.backgroundColor=_LightGrey;
    
    
    UIView *topview2=[UIView new];
    [view addSubview:topview2];
    [topview2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    
    UILabel *label3=[UILabel new];
    [topview2 addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    label3.textColor=_backgroundColor;
    label3.text=@"取消";
    label3.font=[UIFont systemFontOfSize:18];
    
    topview2.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(queXiao:)];
    [topview2 addGestureRecognizer:tapGesture2];
    
    
    UIView *viewa=[UIView new];
    [self addSubview:viewa];
    [viewa mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(view.mas_top);
    }];
    viewa.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture3= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(queXiao:)];
    [viewa addGestureRecognizer:tapGesture3];
}
-(void)fenXian:(UITapGestureRecognizer *)tap{
    if (tap.view.tag==0) {
          [self creatFenXiangToWeiXin];
    }
    if (tap.view.tag==1) {
        [self creatFenXiangToWeiXin2];
    }
}


-(void)queXiao:(id)sender{

    [self removeFromSuperview];
    
}
-(void)creatFenXiangToWeiXin{
    SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
    sendReq.bText = NO;//不使用文本信息
    sendReq.scene =0;//0 = 好友列表 1 = 朋友圈 2 = 收藏
    
    //创建分享内容对象
    WXMediaMessage *urlMessage = [WXMediaMessage message];
    urlMessage.title = _kLinkTitle;//分享标题
    urlMessage.description =@"";//分享描述
    [urlMessage setThumbImage:[UIImage imageNamed:@"log"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
    //创建多媒体对象
    WXWebpageObject *webObj = [WXWebpageObject object];
    webObj.webpageUrl =[NSString stringWithFormat:@"%@/index/news/newslist_details/news_id/%@",_addressUrl,_themID];//分享链接
    
    //完成发送对象实例
    urlMessage.mediaObject = webObj;
    sendReq.message = urlMessage;
    
    //发送分享信息
    [WXApi sendReq:sendReq];
    [self queXiao:nil];
}
-(void)creatFenXiangToWeiXin2{
    SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
    sendReq.bText = NO;//不使用文本信息
    
    sendReq.scene =1;//0 = 好友列表 1 = 朋友圈 2 = 收藏
    //创建分享内容对象
    WXMediaMessage *urlMessage = [WXMediaMessage message];
    urlMessage.title = _kLinkTitle;//分享标题
    urlMessage.description = @"";//分享描述
    [urlMessage setThumbImage:[UIImage imageNamed:@"log"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
    //创建多媒体对象
    WXWebpageObject *webObj = [WXWebpageObject object];
    webObj.webpageUrl =[NSString stringWithFormat:@"%@/index/news/newslist_details/news_id/%@",_addressUrl,_themID];//分享链接
    
    //完成发送对象实例
    urlMessage.mediaObject = webObj;
    sendReq.message = urlMessage;
    
    //发送分享信息
    
    NSLog(@"%d",[WXApi sendReq:sendReq]);
    [self queXiao:nil];
}


@end
